<?php

require_once('to/AyNoMemes.php');

class AyNoMemesDAO {
    const SEL_TOP_MEME = "SELECT * FROM ay_no_memes WHERE status='A' ORDER BY fechaPublicacion DESC, id DESC LIMIT 1";
	const SEL_TOP_25_MEMES = "SELECT * FROM ay_no_memes WHERE status='A' ORDER BY fechaPublicacion DESC, id DESC LIMIT 25";

    public static function getTopMeme() {
        $sSql = self::SEL_TOP_MEME;

        $DB = DBFunctions::getInstance();
        $arrMemes = $DB->execSelect($sSql, array());

        return self::populate($arrMemes);
    }

	public static function getTop25Memes() {
		$sSql = self::SEL_TOP_25_MEMES;

		$DB = DBFunctions::getInstance();
		$arrMemes = $DB->execSelect($sSql, array());

		return self::populate($arrMemes);
	}

    private static function populate($arrMemes){

        $objMemes = array();

        foreach($arrMemes as $A){
            $objMeme = new AyNoMemes();
            $objMeme->setId($A["id"]);
            $objMeme->setFoto($A["foto"]);
            $objMeme->setDescripcion($A["descripcion"]);
            $objMeme->setFechaPublicacion($A["fechaPublicacion"]);
            $objMeme->setStatus($A["status"]);

            array_push($objMemes, $objMeme);
        }
        return $objMemes;
    }
}